import { getConfig, setConfig } from "../../config";
const config = getConfig();
const state = {
	userName: "LinMing",
	theme: config.theme
};

const mutations = {
	CHANGE_THEAM(state, data) {
		state.theme = data;
	}
};

const actions = {
	changeTheme({ commit, state }) {
		console.log("state.theme", state.theme);

		const newTheme = state.theme === "light" ? "dark" : "light";
		console.log("newTheme", newTheme);

		commit("CHANGE_THEAM", newTheme);
		setConfig({ theme: newTheme });
	}
};

export default {
	namespaced: true,
	state,
	mutations,
	actions
};
